﻿/* 
 * Since 2008 - 2012
 */

package com.hh.bss.report.service.impl;
import java.io.Serializable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;

import com.hh.bss.base.*;
import com.hh.bss.common.ConstantDic;
import com.hh.bss.common.page.*;
import com.hh.bss.common.page.impl.*;
import com.hh.bss.report.dao.AccountReportDao;
import com.hh.bss.report.service.AccountReportService;
import com.hh.bss.report.vo.query.ReportQuery;
import com.hh.bss.sysadmin.dao.*;
import com.hh.bss.sysadmin.entity.*;
import com.hh.bss.sysadmin.service.*;
import com.hh.bss.sysadmin.vo.query.*;
import com.hh.bss.util.*;




@Service
public class AccountReportServiceImpl extends BaseBusinessService<SystemAuditLog,java.lang.Integer>  implements AccountReportService<SystemAuditLog,java.lang.Integer>{
	private AccountReportDao accountReportDao;
	public void setAccountReportDaoImpl(AccountReportDao accountReportDao){
		this.accountReportDao=accountReportDao;
	}
	public List accountYJSum(ReportQuery query){
		List l=accountReportDao.accountYJSum(query);
		Map m=accountReportDao.accountYJSumTotal(query);
		DBUtil.sumXjTotal("name",l, m, false,true);		
		return l;
	}

	public List workKpi(ReportQuery query){
		return accountReportDao.workKpi(query);
	}
	
	public EntityDao getEntityDao() {
		// TODO Auto-generated method stub
		return null;
	}
	
	public List jobmonitor(ReportQuery query) {
		// TODO Auto-generated method stub
		return accountReportDao.jobmonitor(query);
	}
	
	public Page jobeff(ReportQuery query) {
		// TODO Auto-generated method stub
		return accountReportDao.jobeff(query);
	}
	
	public Page jobsum(ReportQuery query) {
		// TODO Auto-generated method stub
		Page page=accountReportDao.jobsum(query);
		List l=page.getResult();
		//System.out.println("jobsum:"+l);
		//System.out.println("jobsum dso:"+((Map)l.get(0)).get("dso").getClass().toString());
		
		for(int i=0;i<l.size();i++){
			Map m=(Map)l.get(i);
			Long v=(Long)m.get("dso");
			 // 1110222-没有实际上班日期;3330555-未回款
			if (v!=null){
				if ("1110222".equals(v.toString())) m.put("dso", "无实际上班日");
				if ("3330555".equals(v.toString())) m.put("dso", "未回款");
			}
			
				
		}
		
		//增加合计行
		Map m=accountReportDao.jobsumTotal(query);
		//DBUtil.sumXjTotal("jobManager",l, m, false,false,"");
		DBUtil.sumJobSumXjTotal("jobManager",l, m, false,false,"Average",true);
		return page;
	} 	
	//个人业绩总结
	public List myYJ(ReportQuery query){
		List l=accountReportDao.myyj(query);
		Map m=accountReportDao.myyjTotal(query);
		DBUtil.sumXjTotal("custName",l, m, true,false);
		return l;
	}
	public List bothYJ(ReportQuery query){
		List l=accountReportDao.bothyj(query);
		List tl=accountReportDao.bothyjTotal(query);
        Map m=new HashMap();
		//System.out.println("bothYj:"+tl);
		if(tl!=null&&tl.size()>0) m=(Map)tl.get(0);
		
		DBUtil.sumXjTotal("name",l, m,false,true);
		//System.out.println("after bothYj:"+l);
		if(tl!=null&&tl.size()>1) l.add(tl.get(1));
		
		
		return l;
	}
	public List myOfferYJ(ReportQuery query){
		List l=accountReportDao.myofferyj(query);
		Map m=accountReportDao.myofferyjTotal(query);
		DBUtil.sumXjTotal("custName",l, m, true,false);
		return l;
	}
	
	@Override
	public List bajobsum(ReportQuery query) {
		// TODO Auto-generated method stub
		List l=accountReportDao.bajobsum(query);
		//List l=page.getResult();
		Map m=accountReportDao.bajobsumTotal(query);
		DBUtil.sumXjTotal("account",l, m, false,true);
		return l;
		
	}
	@Override
	public List yjmonitor(ReportQuery query) {
		// TODO Auto-generated method stub
		List l= accountReportDao.yjmonitor(query);
		List tl=accountReportDao.yjmonitorTotal(query);
		Map m=new HashMap();
		
		if(tl!=null&&tl.size()>0) m=(Map)tl.get(0);
		DBUtil.sumXjTotal("account",l, m,false,true);
		if(tl!=null&&tl.size()>1) l.add(tl.get(1));
		if(tl!=null&&tl.size()>2) l.add(tl.get(2));
		//l.add(tl);
		return l;
	}
	@Override
	public List othertarget(ReportQuery query) {
		// TODO Auto-generated method stub
		return accountReportDao.othertarget(query);
	}
	@Override
	public List staffEffAnalyse(ReportQuery query) {
		// TODO Auto-generated method stub
		List l=accountReportDao.staffEffAnalyse(query);
		Map m=accountReportDao.staffEffAnalyseSum(query);
		DBUtil.sumXjTotal("account",l, m, false,true,"Average",false);
		return l;
	}
	@Override
	public Page customerEffAnalyse(ReportQuery query) {
		// TODO Auto-generated method stub
		Page page=accountReportDao.customerEffAnalyse(query);
		List l=page.getResult();
		
		Map m=accountReportDao.customerEffAnalyseSum(query);
		
		DBUtil.sumXjTotal("custName",l, m, false,false,"Average",true);
		return page;
	}
	@Override
	public Page staffDataReport(ReportQuery query) {
		// TODO Auto-generated method stub
		return accountReportDao.staffDataReport(query);
	}
	@Override
	public List jobefflist(ReportQuery query) {
		// TODO Auto-generated method stub
		return accountReportDao.jobefflist(query);
	}
	public List staffDataReportlist(ReportQuery query) {
		// TODO Auto-generated method stub
		List l=accountReportDao.staffDataReportlist(query);
		//转换
		Map m=null; 
		for(int i=0;l!=null&&i<l.size();i++){
			m=(Map)l.get(i);
			m.put("datatype", ConstantDic.getConstantDicCategoryValue(ConstantDic.DataType, ObjectUtils.toString(m.get("datatype"))));
			m.put("optype", ConstantDic.getConstantDicCategoryValue(ConstantDic.OpType, ObjectUtils.toString(m.get("optype"))));
			m.put("integrity", ConstantDic.getConstantDicCategoryValue(ConstantDic.CvIntegrity, ObjectUtils.toString(m.get("integrity"))));
		}
		return l;
	}
}
